﻿using Microsoft.SharePoint;
using System.IO;
using System.Runtime.CompilerServices;
using TIT.OpenXml.Document;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;

namespace OpenXML_FluentDocumentWeb.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected HtmlForm form1;
        public int ID { get; set; }

        public SPListItem itemDocument { get; set; }

        public SPListItem modeloDocumento { get; set; }

        public string SiteUrl { get; set; }

        public string TipoDocumento { get; set; }

        private void Fax()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/Fax.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Tratamento", this.Val(this.itemDocument, "Tratamento")).AddPlaceHolder("Para", this.Val(this.itemDocument, "Para")).AddPlaceHolder("Cargo", this.Val(this.itemDocument, "Cargo:")).AddPlaceHolder("CargoPara", this.Val(this.itemDocument, "Cargo")).AddPlaceHolder("Fax", this.Val(this.itemDocument, "Fax")).AddPlaceHolder("Remetente", this.Val(this.itemDocument, "De")).AddPlaceHolder("NumPaginas", this.Val(this.itemDocument, "NumPaginas")).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddPlaceHolder("Data", this.ValDateTime(this.itemDocument, "Data", "dd/MM/yyyy")).AddHtmlParagraph("Corpo", this.Val(this.itemDocument, "Texto")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=Fax" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void Informativo()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/NotaInformativa.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Setor", this.Val(this.itemDocument, "Setor")).AddPlaceHolder("DataCalc", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Data", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Texto", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=NotaInformativa" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void Delegacao()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/Delegacao.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("DataCalc", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Data", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Texto", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=Delegacao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void Memo()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/Memo.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("De", this.Val(this.itemDocument, "De")).AddPlaceHolder("Para", this.Val(this.itemDocument, "Para")).AddPlaceHolder("CargoDe", this.Val(this.itemDocument, "Cargo")).AddPlaceHolder("ComCopia", this.Val(this.itemDocument, "C/C"), true);
                if (this.Val(this.itemDocument, "C/C").Length > 0)
                {
                    stream2.AddPlaceHolder("CargoCopia", this.Val(this.itemDocument, "Cargo C/C"));
                }
                stream2.AddPlaceHolder("CargoPara", this.Val(this.itemDocument, "Cargo:")).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddPlaceHolder("Assinatura", this.Val(this.itemDocument, "De").ToUpper()).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=Memo" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void NotaTecnica()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/NotaTecnica.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).AddPlaceHolder("Numero", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("De", this.Val(this.itemDocument, "De")).AddPlaceHolder("Para", this.Val(this.itemDocument, "Para")).AddPlaceHolder("CargoDe", this.Val(this.itemDocument, "Cargo")).AddPlaceHolder("CargoPara", this.Val(this.itemDocument, "Cargo:")).AddPlaceHolder("C/C", this.Val(this.itemDocument, "C/C"), true);
                if (this.Val(this.itemDocument, "C/C").Length > 0)
                {
                    stream2.AddPlaceHolder("CargoCopia", this.Val(this.itemDocument, "Cargo C/C"));
                }
                stream2.AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Alcada", this.Val(this.itemDocument, "Alçada")).AddHtmlParagraph("Objeto", this.Val(this.itemDocument, "Objeto")).AddHtmlParagraph("Orcamento", this.Val(this.itemDocument, "Orçamento")).AddHtmlParagraph("Informacoes", this.Val(this.itemDocument, "Informações/Histórico")).AddHtmlParagraph("Justificativa", this.Val(this.itemDocument, "Justificativa")).AddHtmlParagraph("Proposta", this.Val(this.itemDocument, "Proposta")).AddHtmlParagraph("Manifestacoes", this.Val(this.itemDocument, "Manifestações")).AddHtmlParagraph("Despacho", this.Val(this.itemDocument, "Despacho")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=NotaTecnica" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void Oficio()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/Oficio.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Data", this.ValDateTime(this.itemDocument, "Data", "yyyy")).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).AddPlaceHolder("DataCalc", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("Tratamento", this.Val(this.itemDocument, "Tratamento")).AddPlaceHolder("Para", this.Val(this.itemDocument, "Para").ToUpper()).AddPlaceHolder("Entidade", this.Val(this.itemDocument, "Entidade")).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddPlaceHolder("Title", this.Val(this.itemDocument, "De").ToUpper()).AddPlaceHolder("Cargo", this.Val(this.itemDocument, "Cargo")).AddHtmlParagraph("Texto", this.Val(this.itemDocument, "Texto")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=Oficio" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ID = int.Parse(base.Request["tipoid"]);
            this.TipoDocumento = base.Server.UrlDecode(base.Request["t"]);
            this.SiteUrl = SPContext.Current.Site.Url;
            this.itemDocument = SPContext.Current.Web.Lists["correspondência"].Items.GetItemById(this.ID);
            switch (TipoDocumento) { 
                case "Memo":
                    Memo();
                    break;

                case "Portaria":
                    Portaria();
                    break;

                case "Resolução":
                    Resolucao();
                    break;

                case "Nota Informativa":
                    Informativo();
                    break;

                case "Nota Técnica":
                    NotaTecnica();
                    break;

                case "Ofício":
                    Oficio();
                    break;

                case "Fax":
                    Fax();
                    break;

                case "Delegação":
                    Delegacao();
                    break;
                case "Deliberação da Presidência":
                    DeliberacaoPresidencia();
                    break;
                case "Deliberação da Direx":
                    DeliberacaoDirex();
                    break;
                case "Circular Normativa":
                    CircularNormativo();
                    break;
                case "Resolução do Conselho Deliberativo":
                    ResolucaoConselho();
                    break;


            }
            //SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(this, (IntPtr) this.Page_Load(sender, e));
        }
        private void CircularNormativo()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/circularNormativo.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=resolucao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void DeliberacaoDirex()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/deliberacaoDirex.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=resolucao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void DeliberacaoPresidencia()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/deliberacaoPresidencia.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=resolucao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void ResolucaoConselho()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/resolucaoConselho.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=resolucao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }
        private void Portaria()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/portaria.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Cargo", this.Val(this.itemDocument, "Cargo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("DataExtenso2", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ")).AddPlaceHolder("Tratamento", this.Val(this.itemDocument, "Tratamento")).AddPlaceHolder("Title", this.Val(this.itemDocument, "De").ToUpper()).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=portaria" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private void Resolucao()
        {
            byte[] buffer = SPContext.Current.Web.GetFile(string.Format("{0}{1}", SPContext.Current.Web.Url, "/modeloCorrespondencia/resolucao.docx")).OpenBinary();
            MemoryStream stream = new MemoryStream();
            stream.Write(buffer, 0, buffer.Length);
            using (OpenXmlDocumentStream stream2 = OpenXmlDocument.Open(stream))
            {
                stream2.AddPlaceHolder("Processo", this.Val(this.itemDocument, "Processo")).AddPlaceHolder("Ano", this.ValAno(this.itemDocument, "Data")).AddPlaceHolder("DataExtenso", this.ValDateTime(this.itemDocument, "Data", @"d \de MMMM \de yyyy ").ToUpper()).AddPlaceHolder("Assunto", this.Val(this.itemDocument, "Assunto")).AddHtmlParagraph("Conteudo", this.Val(this.itemDocument, "Texto")).AddPlaceHolder("Assinatura1", this.Val(this.itemDocument, "assinatura1").ToUpper(), true).AddPlaceHolder("Assinatura2", this.Val(this.itemDocument, "assinatura2").ToUpper(), true).AddPlaceHolder("Assinatura3", this.Val(this.itemDocument, "assinatura3").ToUpper(), true).AddPlaceHolder("Cargo1", this.Val(this.itemDocument, "cargo1"), true).AddPlaceHolder("Cargo2", this.Val(this.itemDocument, "cargo2"), true).AddPlaceHolder("Cargo3", this.Val(this.itemDocument, "cargo3"), true).AddPlaceHolder("Area", this.Val(this.itemDocument, "Área")).Finish();
                stream2.Save();
                base.Response.Clear();
                base.Response.BufferOutput = false;
                base.Response.ContentType = "application/msword";
                base.Response.AppendHeader("content-disposition", "attachment;filename=resolucao" + this.ID + ".docx");
                stream.WriteTo(base.Response.OutputStream);
            }
        }

        private string Val(SPListItem item, string col)
        {
            try
            {
                string str = item[col].ToString();
                if (str.Contains(";#"))
                {
                    str = str.Remove(0, str.IndexOf("#") + 1);
                }
                return str;
            }
            catch
            {
                return "";
            }
        }

        private string ValAno(SPListItem item, string col)
        {
            try
            {
                return Convert.ToDateTime(item[col].ToString()).Year.ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        private string ValDateTime(SPListItem item, string col, string format)
        {
            try
            {
                return Convert.ToDateTime(item[col].ToString()).ToString(format);
            }
            catch
            {
                return "EXCEPTION";
            }
        }
    }
}
